package Demo0;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        Staff staff1=new Staff("张三",20,3000);
        Staff staff2=new Staff("李四",23,3400);
        Staff staff = new Staff("Tom", 30, 5000);
        File file = new File("E:\\22\\test.txt");
        List<Staff> list=new ArrayList<Staff>();
        list.add(staff1);
        list.add(staff2);
        list.add(staff);

        staff.saveStaffToFile(new Staff("Tom", 30, 5000),new File("E:\\22\\test.txt"));
        ObjectOutputStream oos=null;
        ObjectInputStream ois=null;
        try {
            oos=new ObjectOutputStream(new FileOutputStream("E:\\22\\test1.txt"));
            oos.writeObject(list);
            oos=new ObjectOutputStream(new FileOutputStream("E:\\22\\staff1.txt"));
            oos.writeObject(staff1);
            oos=new ObjectOutputStream(new FileOutputStream("E:\\22\\staff2.txt"));
            oos.writeObject(staff2);
            oos=new ObjectOutputStream(new FileOutputStream("E:\\22\\test.txt"));
            oos.writeObject(staff);
            ois=new ObjectInputStream(new FileInputStream("E:\\22\\staff1.txt"));
            Staff v1=(Staff) ois.readObject();
            ois=new ObjectInputStream(new FileInputStream("E:\\22\\staff2.txt"));
            Staff v2=(Staff)ois.readObject();
            System.out.println(v1.getName()+"\t"+v1.getAge()+"\t"+v1.getSalary());
            System.out.println(v2.getName()+"\t"+v2.getAge()+"\t"+v2.getSalary());

        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } finally {
            try {
                oos.close();
                ois.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
